<template>
	<view>
		<view class="wrap">
			<view class="u-tabs-box">
				<u-tabs activeColor="#f29100" ref="tabs" :list="list" :current="current" @change="change"
					:is-scroll="false" swiperWidth="750"></u-tabs>
			</view>
			<swiper class="swiper-box" :current="swiperCurrent" @animationfinish="animationfinish">
				<swiper-item class="swiper-item" v-for="(orderlist, index) in orderList" :key="index">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom"
						v-if="orderlist.length !== 0">
						<view class="page-box">
							<view class="order" v-for="(res, index) in orderlist" :key="res.thirdOrderNo">
								<view class="top">
									<view class="left">
										<u-icon name="home" :size="30" color="rgb(94,94,94)"></u-icon>
										<view class="store">{{ res.thirdOrderNo }}</view>
										<u-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></u-icon>
									</view>
									<view class="right">{{ res.orderStatus }}</view>
								</view>
								<view class="item" v-for="(item, index) in res.details" :key="index">
									<view class="left">
										<image :src="item.itemImg" mode="aspectFill"></image>
									</view>
									<view class="content">
										<view class="title u-line-2">{{ item.itemAlias? item.itemAlias:item.itemName }}
										</view>
										<view class="type">sku: {{ item.skuCode }}</view>
										<view class="type">品牌: {{ item.itemBrand }}</view>
										<view class="type">尺码: {{ item.itemSize }}</view>
										<view class="type">支付方式: {{ res.payMethod }}</view>
										<view class="type">渠道: {{ res.orderSource }}</view>
										<view class="delivery-time">下单时间: {{ res.placedAt }}</view>
									</view>
									<view class="right">
										<view class="price">
											￥{{ item.costPrice }}
										</view>
										<view class="number">x{{ item.itemNum }}</view>
									</view>
								</view>
								<view class="total">
									共{{ res.productCount }}件商品 合计:
									<text class="total-price">
										￥{{ res.orderAmount }}
									</text>
								</view>
					<!-- 			<view class="bottom">
									<view class="more"><u-icon name="more-dot-fill" color="rgb(203,203,203)"></u-icon>
									</view>
									<view class="logistics btn">查看物流</view>
									<view class="exchange btn">卖了换钱</view>
									<view class="evaluate btn">评价</view>
								</view> -->
							</view>
							<u-loadmore :status="loadStatus[0]" bgColor="#f2f2f2"></u-loadmore>
						</view>
					</scroll-view>
			<scroll-view scroll-y style="height: 100%;width: 100%;" v-else>
				<view class="page-box">
					<view>
						<view class="centre">
							<image src="https://cdn.uviewui.com/uview/template/taobao-order.png" mode="">
							</image>
							<view class="explain">
								您还没有相关的三方订单
								<view class="tips">请联系作者添加权限</view>
							</view>
							<view class="btn">随便逛逛</view>
						</view>
					</view>
				</view>
			</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>



<script>
	// pages/system/user/index.vue
	import {
		listOrder
	} from "@/api/work/order/order.js";

	export default {
		data() {
			return {
				nextPageFlag: [
					true, true, true, true
				],
				query: [{
					pageNum: 1,
					pageSize: 10,
					orderStatus: ''
				}, {
					pageNum: 1,
					pageSize: 10,
					orderStatus: ''
				}],
				orderList: [
					[],
					[],
					[],
					[]
				],
				list: [{
						name: '配送中',
						status: 'SHIPPED'
					},
					{
						name: '已收货',
						status: 'DELIVERED'
					},
					{
						name: '待收货'
					},
					{
						name: '待评价',
						count: 12
					}
				],
				totalCount: [0,0,0,0],
				current: 0,
				swiperCurrent: 0,
				loadStatus: ['loadmore', 'loadmore', 'loadmore', 'loadmore'],
			};
		},
		onLoad() {
			this.getOrderList(0);
			this.getOrderList(1);
			// this.getOrderList(3);
		},
		computed: {

		},
		methods: {
			// 触底懒加载
			reachBottom() {
				console.info("触底----开始加在orderList")
				this.loadStatus.splice(this.current, 1, "loading")
				if (this.nextPageFlag[this.current]) {
					setTimeout(() => {
						console.info("延迟1.1s")
						this.getOrderList(this.current);
					}, 1100);
				}

			},
			// 页面数据
			getOrderList(idx) {
				this.nextPageFlag[idx] = false;
				const pageTotal = this.totalCount[idx] / this.query[idx].pageSize
				console.info('pageTotal:' + pageTotal)
				console.info('pageNum:' + this.query[idx].pageNum)
				if (true) {
					this.query[idx].orderStatus = this.list[idx].status
					setTimeout(() => {
					listOrder(this.query[idx]).then(response => {
						this.orderList[idx].push(...response.rows)
						this.totalCount[idx] = response.total
						//如果 rows.length<pageSize,说明没有下一页了
						if(response.rows.length<this.query[idx].pageSize){
							this.nextPageFlag[idx] = false;
						}else{
							this.query[idx].pageNum++
							this.nextPageFlag[idx] = true;
						}
					})
					},500)
					this.loadStatus.splice(this.current, 1, "loadmore")
				}else{
					this.loadStatus.splice(this.current, 1, "noMore")
				}


				// 模拟第n个页面获取数据
				// for (let i = 0; i < 5; i++) {
				// 	let index = this.$u.random(0, this.dataList.length - 1);
				// 	let data = JSON.parse(JSON.stringify(this.dataList[index]));
				// 	data.id = this.$u.guid();
				// 	this.orderList[idx].push(data);
				// }
			},
			// tab栏切换
			change({
				index
			}) {
				this.swiperCurrent = index;
				this.getOrderList(index);
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				this.swiperCurrent = current;
				this.current = current;
			}
		}
	};
</script>

<style>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #f2f2f2;
	}

	/* #endif */
</style>

<style lang="scss" scoped>
	.order {
		width: 710rpx;
		background-color: #ffffff;
		margin: 20rpx auto;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 28rpx;

		.top {
			display: flex;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;

				.store {
					margin: 0 10rpx;
					font-size: 32rpx;
					font-weight: bold;
				}
			}

			.right {
				color: $u-warning-dark;
			}
		}

		.item {
			display: flex;
			margin: 20rpx 0 0;

			.left {
				margin-right: 20rpx;

				image {
					width: 200rpx;
					height: 200rpx;
					border-radius: 10rpx;
				}
			}

			.content {
				flex: 1;
				.title {
					font-size: 28rpx;
					line-height: 50rpx;
				}

				.type {
					margin: 10rpx 0;
					font-size: 24rpx;
					color: $u-tips-color;
				}

				.delivery-time {
					color: #e5d001;
					font-size: 24rpx;
				}
			}

			.right {
				margin-left: 10rpx;
				padding-top: 20rpx;
				text-align: right;

				.decimal {
					font-size: 24rpx;
					margin-top: 4rpx;
				}

				.number {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
		}

		.total {
			margin-top: 20rpx;
			text-align: right;
			font-size: 24rpx;

			.total-price {
				font-size: 32rpx;
			}
		}

		.bottom {
			display: flex;
			margin-top: 40rpx;
			padding: 0 10rpx;
			justify-content: space-between;
			align-items: center;

			.btn {
				line-height: 52rpx;
				width: 160rpx;
				border-radius: 26rpx;
				border: 2rpx solid $u-border-color;
				font-size: 26rpx;
				text-align: center;
				color: $u-info-dark;
			}

			.evaluate {
				color: $u-warning-dark;
				border-color: $u-warning-dark;
			}
		}
	}

	.centre {
		text-align: center;
		margin: 200rpx auto;
		font-size: 32rpx;

		image {
			margin: 0 auto;
			width: 164rpx;
			height: 164rpx;
			border-radius: 50%;
			margin-bottom: 20rpx;
		}

		.tips {
			font-size: 24rpx;
			color: #999999;
			margin-top: 20rpx;
		}

		.btn {
			margin: 80rpx auto;
			width: 200rpx;
			border-radius: 32rpx;
			line-height: 64rpx;
			color: #ffffff;
			font-size: 26rpx;
			background: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
		}
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}
</style>